package org.budo.dubbo.protocol.http.dispatcher.cometd;

import java.util.Map;

import org.budo.dubbo.protocol.http.invocation.adapter.ProtocolRequest;
import org.budo.support.lang.util.StringUtil;
import org.cometd.bayeux.server.ServerMessage.Mutable;

/**
 * @author li
 */
public class CometdProtocolRequest implements ProtocolRequest {
    private Map<String, Object> messageData;

    public CometdProtocolRequest(Mutable message) {
        this.messageData = message.getDataAsMap();
    }

    public String getInterfaceName() {
        return StringUtil.toString(messageData.get("interfaceName"));
    }

    public String getMethodName() {
        return StringUtil.toString(messageData.get("methodName"));
    }

    public String getRequestId() {
        return StringUtil.toString(messageData.get("requestId"));
    }

    public Map<String, Object> getArguments() {
        Object _args = messageData.get("args");
        return (Map<String, Object>) ((Object[]) _args)[0];
    }

    @Override
    public String toString() {
        return super.toString() + ", messageData=" + this.messageData;
    }

    @Override
    public String getHeader(String name) {
        throw new RuntimeException();
    }

    @Override
    public String getRemoteAddr() {
        throw new RuntimeException();
    }

    @Override
    public Integer getRemotePort() {
        throw new RuntimeException();
    }
}